package ua.tach.shortl.logic;

import com.badlogic.gdx.math.Vector2;

public class Point {
	public static final int VIRTUAL_COUNTRY_SIZE = Country.VIRTUAL_COUNTRY_SIZE;
	private static final int[][] CITY_COORDINATES = {
		{0,4}, {2,6}, {4,8}, {4, 0}, {6, 2}, {8,4}
	};
	
	public int x;
	public int y;

	public Point () {
		x=0;
		y=0;
	}

	public Point(int px, int py) {
		x= px;
		y= py;
	}
	
	public Point (Point pp) {
		x = pp.x;
		y = pp.y;
	}

	public Point set (int px, int py) {
		x = px;
		y = py;
		return this;
	}

	public Point set (Point pp) {
		x = pp.x;
		y = pp.y;
		return this;
	}

	public Point add(int px, int py) {
		x += px;
		y += py;
		return this;
	}

	public Point add(Point p) {
		x += p.x;
		y += p.y;
		return this;
	}

	public boolean isCorrectCoordinate() {
		if( x < 0 || y < 0 || x > VIRTUAL_COUNTRY_SIZE-1 || y > VIRTUAL_COUNTRY_SIZE-1 || x+y < 2 || x+y > 14 || x-y > 3 || y-x > 3 ) return false;
		return true;
	}

	public boolean isCorrectCoordinate(Point d) {
		if( x < 0 || y < 0 || x > VIRTUAL_COUNTRY_SIZE-1 || y > VIRTUAL_COUNTRY_SIZE-1 ||
				x+d.x < 0 || y+d.y < 0 || x+d.x > VIRTUAL_COUNTRY_SIZE-1 || y+d.y > VIRTUAL_COUNTRY_SIZE-1 ||
				x+y < 2 || x+y > 14 || x-y > 3 || y-x > 3 ||
				x+d.x+y+d.y < 2 || x+d.x+y+d.y > 14 || x+d.x-y-d.y> 3 || y+d.y-x-d.x > 3 ) return false;
		return true;
	}

	public boolean isUnavail() {
		if(x+y < 2 || x+y > 14 || x-y > 3 || y-x > 3 ) return true;
		return false;
	}

	public int getIndex () {
		return x*VIRTUAL_COUNTRY_SIZE+y;
	}

	public int getIndex (Point d) {
		return (x+d.x)*VIRTUAL_COUNTRY_SIZE+y+d.y;
	}

	public boolean compareTo(Vector2 v) {
		if (Math.round(v.x) == x && Math.round(v.y) == y) return true;
		return false;
	}
	
	public boolean isCityCoordinate() {
		for (int[] c : CITY_COORDINATES) {
			if(x == c[0] && y == c[1] ) return true;
		}
		return false;
	}
	
	@Override public String toString() {
	    StringBuilder result = new StringBuilder();
	    result.append(" X=" + x + " Y=" + y);
	    return result.toString();
	  }

	
}
